/*************************************************************************
 * CS516 Software Engineering
 * Group Project: Android Finance Management System
 * DBOpenHelper.java
 * The database class file helps the application create tables and connect to the SQLite 
 *************************************************************************/
package com.svu.se.group3;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * (add your name below)
 * @author A2303 Lei Jiang
 * @author A2316 Keerthi Aleti
 */
public class DBOpenHelper extends SQLiteOpenHelper {

	 private static final int DATABASE_VERSION = 3;
	 private static final String DATABASE_NAME = "transactions.db";
	 public static final String TRANSACTION_TABLE_NAME = "transactions";
	 private static final String TRANSACTION_TABLE_CREATE =
	                "CREATE TABLE IF NOT EXISTS "+TRANSACTION_TABLE_NAME+
	                " (id INTEGER PRIMARY KEY, "+
	                "product_name VARCHAR(20),"+
	                "category VARCHAR(20),"+
	                "quantity INTEGER,"+
	                "price FLOAT(11, -2),"+
	                "purchase_date VARCHAR(20));";
	 public static final String ID = "id";
	 public static final String PRODUCT_NAME = "product_name";
	 public static final String CATEGORY = "category";
	 public static final String QUANTITY = "quantity";
	 public static final String PRICE = "price";
	 public static final String PURCHASE_DATE = "purchase_date";

	/**
	 * @param context
	 * @param name
	 * @param factory
	 * @param version
	 */
	public DBOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	/* (non-Javadoc)
	 * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
	 * onCreate is called when the object is created
	 * check if tables exist, if not, create new one.
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		// Creating 'transaction' table in the SQLiteDatabase.
		db.execSQL(TRANSACTION_TABLE_CREATE);		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}
	

}
